package de.ubschmidt.capi;

/**
 * Definition of possible values for the message parameter Info.
 */
public enum ErrorInfo {
    /**
     * No error, request accepted.
     */
    REQUEST_ACCEPTED(0),

    /**
     * NCPI not supported by current protocol, NCPI ignored.
     */
    NCPI_NOT_SUPPORTED_OR_IGNORED(0x0001),

    /**
     * Flags not supported by current protocol, flags ignored.
     */
    FLAGS_NOT_SUPPORTED_OR_IGNORED(0x0002),

    /**
     * Alert already sent by another application.
     */
    ALERT_ALREADY_SENT(0x0003),

    /**
     *
     */
    x2001(0x2001),

    /**
     *
     */
    ILLEGAL_CONTROLLER(0x2002),

    /**
     *
     */
    NO_PLCI_AVAILABLE(0x2003),

    /**
     *
     */
    ILLEGAL_MESSAGE_PARAMETER_CODING(0x2007),

    /**
     *
     */
    B1_PROTOCOL_NOT_SUPPORTED(0x3001),

    /**
     *
     */
    B2_PROTOCOL_NOT_SUPPORTED(0x3002),

    /**
     *
     */
    B3_PROTOCOL_NOT_SUPPORTED(0x3003),

    /**
     *
     */
    B1_PROTOCOL_PARAMETER_NOT_SUPPORTED(0X3004),

    /**
     *
     */
    B2_PROTOCOL_PARAMETER_NOT_SUPPORTED(0X3005),

    /**
     *
     */
    B3_PROTOCOL_PARAMETER_NOT_SUPPORTED(0X3006),

    /**
     *
     */
    B_PROTOCOL_COMBINATION_NOT_SUPPORTED(0x3007),

    /**
     *
     */
    CIP_VALUE_UNKNOWN(0x3009),

    ANOTHER_APPLICATION_GOT_THAT_CALL(0x3304),

    /**
     *
     */
    CHANNEL_UNACCEPTABLE(0x3486),

    /**
     *
     */
    NORMAL_CALL_CLEARING(0x3490),

    /**
     *
     */
    USER_BUSY(0x3491),

    /**
     *
     */
    NO_USER_RESPONDING(0x3492),

    /**
     *
     */
    DESTINATION_OUT_OF_ORDER(0x349b),

    /**
     *
     */
    NORMAL_UNSPECIFIED(0x349f),

    /**
     *
     */
    INCOMPATIBLE_DESTINATION(0x34d8);

    /**
     * Define a new {@code ErrorInfo} enum which represents the specified
     * Info value.
     *
     * @param value The value of the Info parameter.
     */
    ErrorInfo(final int value) {
        _value = (short) value;
    }

    /**
     * Retrieve the enum representing the specified value of the Info parameter.
     *
     * @param value The value of the Info parameter.
     * @return An {@code ErrorInfo} enum representing the specified Info value.
     * @throws IllegalArgumentException An {@code IllegalArgumentException}
     *                                  is thrown if the value is not known.
     */
    public static ErrorInfo valueOf(final short value)
            throws IllegalArgumentException {
        ErrorInfo [] enums = values();

        for (int i = 0; i < enums.length; ++i) {
            if (enums[i].getValue() == value) {
                return enums[i];
            }
        }

        throw new IllegalArgumentException(
                String.format("unknown value 0x%04x for ErrorInfo", value));
    }

    /**
     *
     * @return
     */
    public short getValue() {
        return _value;
    }

    /** {@inheritDoc} */
    @Override
    public String toString() {
        String s = String.format("%s(0x%04x)",
                this.name(),
                getValue());

        return s;
    }

    /** The value of the Info parameter. */
    private short _value;
}


/*
 * from http://www.uni-koeln.de/rrzk/netze/isdn/errors.htm
 *

2001 Message not supported in current state
2002 Illegal Controller / PLCI / NCCI
2003 Out of PLCI
2004 Out of NCCI
2005 Out of LISTEN
2007 llegal message parameter coding
3001 B1 protocol not supported
3002 B2 protocol not supported
3003 B3 protocol not supported
3004 B1 protocol parameter not supported
3005 B2 protocol parameter not supported
3006 B3 protocol parameter not supported
3007 B protocol combination not supported
3008 NCPI not supported
3009 CIP Value unknown
300A Flags not supported (reserved bits)
300B Facility not supported
300C Data length not supported by current protocol
300D Reset procedure not supported by current protocol
3301 Protocol error layer 1 (broken line or B-channel removed by signalling
     protocol)
3302 Protocol error layer 2
3303 Protocol error layer 3
3304 Another application got that call
3480 Normal termination
3481 Unallocated (unassigned) number
3482 No route to specified transit network
3483 No route to destination
3486 Channel unacceptable
3487 Call awarded and being delivered in an established channel
3490 Normal call clearing
3491 User busy
3492 No user responding
3493 No answer from user (user alerted)
3495 Call rejected
3496 Number changed
349A Non-selected user clearing
349B Destination out of order
349C Invalid number format
349D Facility rejected
349E Response to STATUS ENQUIRY
349F Normal, unspecified
34A2 No circuit / channel available
34A6 Network out of order
34A9 Temporary failure
34AA Switching equipment congestion
34AB Access information discarded
34AC Requested circuit / channel not available
34AF Resources unavailable, unspecified
34B1 Quality of service unavailable
34B2 Requested facility not subscribed
34B9 Bearer capability not authorized
34BA Bearer capability not presently available
34BF Service or option not available, unspecified
34C1 Bearer capability not implemented
34C2 Channel type not implemented
34C5 Requested facility not implemented
34C6 Only restricted digital information bearer capability is available
34CF Service or option not implemented, unspecified
34D1 Invalid call reference value
34D2 Identified channel does not exist
34D3 A suspended call exists, but this call identity does not
34D4 Call identity in use
34D5 No call suspended
34D6 Call having the requested call identity has been cleared
34D8 Incompatible destination
34DB Invalid transit network selection
34DF Invalid message, unspecified
34E0 Mandatory information element is missing
34E1 Message type non-existent or not implemented
34E2 Message not compatible with call state or message type non-existent or
     not implemented
34E3 Information element non-existent or not implemented
34E4 Invalid information element contents
34E5 Message not compatible with call state
34E6 Recovery on timer expiry
34EF Protocol error, unspecified
34FF Interworking, unspecified

 */
